// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env:"cloud1-9gi73u0tdf91dfdb"})

// 云函数入口函数
exports.main = async (event, context) => {
  cloud.database().collection('user_Info').where({
    openid:event.openid
  }).get().then(res=>{
    if(res.data.length==0)
    {
      cloud.database().collection('user_Info').add({
        data:{
          openid:event.openid,
          name:event.name,
          img:event.img,
          gender:"",
          campus:"",
          grade:"",
          hobby:"",
          friend:[],
          myMessage:[],
          myAnswer:[],
          myPublish:[]
        },
        sucess(res){
          return res
        },
        fail(err){
          return err
        }
      })
    }
}).catch(err=>{
  console.log(err)//打印错误信息
})

}